package org.geektimes.config.microprofile.source;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.geektimes.common.util.PropertiesUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @FileName: LocalFilePropertiesConfigSource
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2021/3/17 - 下午10:36
 */
public class LocalFilePropertiesConfigSource implements ConfigSource {

    private static final String LOCAL_CONFIG_FILE_NAME = "META-INF/microprofile.properties";

    private Map properties;

    public LocalFilePropertiesConfigSource() {
        Properties properties = PropertiesUtil.loadPropertyFile(LOCAL_CONFIG_FILE_NAME);
        this.properties = new HashMap<>(properties);
    }
    @Override
    public Map<String, String> getProperties() {
        return properties;
    }

    @Override
    public Set<String> getPropertyNames() {
        return properties.keySet();
    }

    @Override
    public int getOrdinal() {
        return 600;
    }

    @Override
    public String getValue(String propertyName) {
        return (String) properties.get(propertyName);
    }

    @Override
    public String getName() {
        return "Local File Properties";
    }
}
